package jiandian;

import java.util.ArrayList;
import java.util.List;

/**
 * 228. 汇总区间
 *输入：nums = [0,2,3,4,6,8,9]
 * 输出：["0","2->4","6","8->9"]
 * @author: luolidong
 * @create: 2021-07-07 19:57
 * @version: 1.0
 */
public class Demo1 {
    public List<String> summaryRanges(int[] nums) {
        List<String> list=new ArrayList<>();
        int fast=0,slow=0;
        while (fast<nums.length){
            if(fast+1<nums.length&&nums[fast+1]==nums[fast]+1){
                fast++;
            }else {
                //不连续
                if(fast==slow)
                    list.add(nums[slow]+"");
                else
                    list.add(nums[slow]+"->"+nums[fast]);
                fast++;
                slow=fast;
            }
        }
        return list;
    }

    public static void main(String[] args) {
        List<String> list = new Demo1().summaryRanges(new int[]{0, 2, 3, 4, 6, 8, 9});
        System.out.println(list);
    }
}
